//Accepted
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

int s, i, j, t, x, y;
int p[]={2,3,5,7};
char d[30], o;

int main (){
	//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
	
	scanf("%d", &t);
	while(t--){
		scanf("%d", &x);
		if(x<10)printf("%d\n",x);
		else{
			s=0;
			y=1;
			j=x;
			while(y<x){
				o=1;
				for(i=9;i>1&&o;--i){
					if(j%i==0){
						y*=i;
						j/=i;
						d[s++]='0'+i;
						o=0;
					}
				}
				if(o){
					y=x+1;
					break;
				}
			}
			if(y==x){
				d[s]='\0';
				sort(d,d+s);
				printf("%s\n",d);
			}
			else printf("-1\n");
		}
	}
	
	return 0;
}
